package com.sec.android.app.myfiles.feature;

import android.content.Context;

import com.sec.android.app.myfiles.feature.privatemode.PrivateModeImp;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.info.AppFeatures;

public class PrivateModeMgr {
    private static PrivateModeMgr mSelf = null;

    public static PrivateModeMgr getInstance(Context context) {
        if (mSelf == null) {
            mSelf = new PrivateModeMgr(context.getApplicationContext());
        }

        return mSelf;
    }

    private PrivateModeImp mPrivateModeImp;

    private PrivateModeMgr(Context context) {
        boolean bPrivateModeManager = true;

        try {
            Class.forName("com.samsung.android.privatemode.SemPrivateModeManager");
        } catch (ClassNotFoundException e) {
            bPrivateModeManager = false;
        }

        if (bPrivateModeManager) {
            mPrivateModeImp = new PrivateModeImp(context);
        } else {
            mPrivateModeImp = null;
        }
    }

    public boolean isPrivateMode() {
        boolean bRet = false;

        if (mPrivateModeImp != null) {
            bRet = mPrivateModeImp.isPrivateMode();
        }

        return bRet;
    }

    public boolean isEnabled() {
        return (!AppFeatures.isAndroidForWork()) && (!AppFeatures.isKnox()) && (isPrivateMode());
    }

    public boolean isPrivateDirMounted() {
        boolean bRet = false;

        if (mPrivateModeImp != null) {
            bRet = mPrivateModeImp.isPrivateDirMounted();
        }

        return bRet;
    }

    public String getRootDir() {
        String ret = AppConstants.StoragePath.PRIVATE_ROOT;

        if (mPrivateModeImp != null) {
            ret = mPrivateModeImp.getRootDir();
        }

        return ret;
    }

    public boolean isPrivateModePath(String path) {
        boolean bRet = false;

        if (mPrivateModeImp != null) {
            bRet = mPrivateModeImp.isPrivateModePath(path);
        }

        return bRet;
    }

    public boolean isReady() {
        boolean bRet = false;

        if (mPrivateModeImp != null) {
            bRet = mPrivateModeImp.isReady();
        }

        return bRet;
    }

    public void createMgr(PrivateStateListener listener) {
        if (mPrivateModeImp != null) {
            mPrivateModeImp.createMgr(listener);
        }
    }

    public void clearMgr(boolean bSucess) {
        if (mPrivateModeImp != null) {
            mPrivateModeImp.clearMgr(bSucess);
        }
    }

    public interface PrivateStateListener {
        void onPrepare(int extInfo);

        void onCancel(int extInfo);

        void onMounted(int extInfo);

        void onUnmounted(int extInfo);
    }

}
